import {defineAsyncComponent, defineComponent, PropType} from "vue";
import {DynamicForm3InstanceType, FormConfigItem} from "../types";

export const BaseCommonMixin=defineComponent({
  components: {
    RenderVnodes: defineAsyncComponent(() => import('../../../components/RenderVnodes3/index.vue')),
  },
  props: {
    formData: {
      type: Object,
      default: {}
    },
    item: {
      type: Object as PropType<FormConfigItem>,
      default: {}
    },
    formVm: {
      type: Object as PropType<DynamicForm3InstanceType>
    }
  },
  computed: {
    comValue() {
      return this.formData[this.item.prop]
    },
  },
  methods: {
    slotName(name) {
      let p = this.item.slotName || this.item.prop
      return p + '_' + name
    },
    hasSlotName(name) {
      const slot = this.formVm.$slots[this.slotName(name)];
      return !!slot
    },
    slot(name, props) {
      const slot = this.formVm.$slots[this.slotName(name)];
      return slot(props)
    },
    sleep(){
      return new Promise(resolve => {
        setTimeout(resolve,200)
      })
    }
  }
})
